﻿package com.badibadi.adapter;

import com.badibadi.activity.ActivityOverViewActivity;
import com.badibadi.activity.AfterLandingActivity;
import com.badibadi.activity.CalendarActivity;
import com.badibadi.activity.CalendarMyActivityActivity;
import com.badibadi.activity.ClubListActivity;
import com.badibadi.activity.ClubMyClubActivity;
import com.badibadi.activity.LogoActivity;
import com.badibadi.activity.MyDataActivity;
import com.badibadi.activity.MyPoly1Activity;
import com.badibadi.activity.RecordAdayToRememberActivity;
import com.badibadi.activity.RecordMyRecordListActivity;
import com.badibadi.infos.UserInfoModel;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.libjph.util.StringUtil;
//import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class AfterLandingRightSlidingFirstAdapter extends BaseAdapter implements
		OnClickListener {

	/**
	 * 0 1 4 11这三个位置特殊位置
	 */
	private String item[] = null;
	// private String
	private int img1[] = {
			R.drawable.ic_launcher,// 占位图片
			R.drawable.ic_launcher,
			R.drawable.orange_weibiao,
			R.drawable.jishiben,
			R.drawable.club_near,
			R.drawable.ic_launcher,// 占位图片
			R.drawable.entermydata,
			R.drawable.mail,
			// 这放咨询费
			R.drawable.said2, R.drawable.afriend, R.drawable.money2,
			R.drawable.b7, R.drawable.b9, R.drawable.b11,
			R.drawable.b4,
			R.drawable.ic_launcher,// 占位图片
			R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4,
			R.drawable.b5, R.drawable.b51, };
	int[] Message = { 0, 0, 0, 0, 0, 0 };

	Context context;
	Intent intent = null;
	UserInfoModel userInfoModel;
	private DisplayImageOptions options;

	public AfterLandingRightSlidingFirstAdapter(Context ct,
			UserInfoModel userInfoModel) {
		// TODO Auto-generated constructor stub
		context = ct;
		this.userInfoModel = userInfoModel;
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		item = new String[] {
				"",
				"",
				context.getResources().getString(R.string.NearTheUser),
				context.getResources().getString(
						R.string.TheActivitiesOfTheNearby),
				context.getResources().getString(
						R.string.TheClubOfTheNearby),
				context.getResources().getString(R.string.AboutMe),
				context.getResources().getString(R.string.mydate),
				context.getResources().getString(
						R.string.The_Previous_Evaluation),
				context.getResources().getString(R.string.cankaoConsultFees),
				context.getResources().getString(R.string.afriend),
				context.getResources().getString(R.string.MoneyNumber),
				context.getResources().getString(R.string.Collection),
				context.getResources().getString(R.string.MyOtherSpace),
				context.getResources().getString(R.string.ManageClub),
				context.getResources().getString(R.string.ApplicationForm),// 这里是申请表
				context.getResources().getString(R.string.clubs),
				context.getResources().getString(R.string.homepage),
				context.getResources().getString(R.string.club),
				context.getResources().getString(R.string.activity),
				context.getResources().getString(R.string.ADayToRemember),
				context.getResources().getString(R.string.BuyingOffice),
				context.getResources().getString(R.string.Logout), };
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return item.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return item[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	// http://www.eoeandroid.com/forum.php?mod=viewthread&tid=200168
	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return super.getItemViewType(position);
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return super.getViewTypeCount();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater layoutInflater;
		LinearLayout l4;
		switch (position) {
		case 0:
			layoutInflater = LayoutInflater.from(context);
			convertView = layoutInflater.inflate(
					R.layout.after_landing_import_layout3, null);
			if (userInfoModel != null) {
				if (!StringUtil.isNullOrEmpty(userInfoModel.getNickName())) {
					// 昵称
					TextView tv_name = (TextView) convertView
							.findViewById(R.id.nickName);
					tv_name.setText("" + userInfoModel.getNickName());
					// 头像
					ImageView iv_head = (ImageView) convertView
							.findViewById(R.id.head);
					ImageView iv_touxiang_daren_youhua = (ImageView) convertView
							.findViewById(R.id.iv_touxiang_daren_youhua);
					iv_head.setOnClickListener(this);

					try {
						if (userInfoModel.getIs_expert() != null
								&& userInfoModel.getIs_expert().equals("1")) {
							iv_touxiang_daren_youhua
									.setVisibility(View.VISIBLE);
						} else {
							iv_touxiang_daren_youhua.setVisibility(View.GONE);
						}
						ImageLoader.getInstance().displayImage(
								Constants.BadiDownImgUrl + "/"
										+ userInfoModel.getHead()
										+ Constants.appPhoto4img, iv_head,
								options);
						// LogUtils.i("170");
					} catch (Exception e) {
						// TODO: handle exception
					}
					LinearLayout is_Line = (LinearLayout) convertView
							.findViewById(R.id.is_Line);
					try {
						// 是否在线
						if (userInfoModel.getIs_login().equals("1")) {
							is_Line.setBackgroundResource(R.drawable.shape_blue_circular_bead);
						} else {
							// is_Line.setBackgroundResource(R.color.gray);
							is_Line.setBackgroundResource(R.drawable.shape_blue_circular_bead);
						}
					} catch (Exception e) {
						// TODO: handle exception
					}

					// is_Line

				}
			}

			ImageButton btn_setting = (ImageButton) convertView
					.findViewById(R.id.after_landing_btn_setting);
			btn_setting.setOnClickListener(this);
			LinearLayout l0 = new LinearLayout(context);
			l0.setLayoutParams(new AbsListView.LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			l0.addView(convertView);

			return l0;
		case 1:
			layoutInflater = LayoutInflater.from(context);
			convertView = layoutInflater.inflate(
					R.layout.after_landing_import_layout4, null);
			ViewHolder holder = new ViewHolder();
			holder.dongtai = (ImageView) convertView.findViewById(R.id.dongtai);
			holder.dongtai
					.setOnClickListener(AfterLandingRightSlidingFirstAdapter.this);
			holder.tupian = (ImageView) convertView.findViewById(R.id.tupian);
			holder.tupian
					.setOnClickListener(AfterLandingRightSlidingFirstAdapter.this);
			holder.jilu = (ImageView) convertView.findViewById(R.id.jilu);
			holder.jilu
					.setOnClickListener(AfterLandingRightSlidingFirstAdapter.this);
			holder.julebu = (ImageView) convertView.findViewById(R.id.julebu);
			holder.julebu
					.setOnClickListener(AfterLandingRightSlidingFirstAdapter.this);
			holder.zhuti = (ImageView) convertView.findViewById(R.id.zhuti);
			holder.zhuti
					.setOnClickListener(AfterLandingRightSlidingFirstAdapter.this);
			return convertView;
			// LinearLayout l1 = new LinearLayout(context);
			// l1.setLayoutParams(new AbsListView.LayoutParams(
			// LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			// convertView.setLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.M);
			// l1.addView(convertView);
		case 5:
			LinearLayout l3 = new LinearLayout(context);
			// ImageView iv=new ImageView(context);
			TextView tv = new TextView(context);
			tv.setText(item[position]);
			tv.setTextSize(DisplayUtil.sp2px(context, 8));
			tv.setPadding(20, 0, 0, 0);
			tv.setTextColor(context.getResources().getColor(R.color.gray_9));
			l3.setBackgroundResource(R.color.gray_e6e6e6);
			l3.addView(tv);
			return l3;

			// case 12://申请表
			//
			// LinearLayout l12 = new LinearLayout(context);
			// // ImageView iv=new ImageView(context);
			// TextView tv1 = new TextView(context);
			// tv1.setText(item[position]);
			// tv1.setTextSize(20);
			// tv1.setPadding(20, 0, 0, 0);
			// tv1.setTextColor(context.getResources().getColor(R.color.gray_9));
			// l12.setBackgroundResource(R.color.gray_e6e6e6);
			// l12.addView(tv1);
			//
			// return l12;
		case 15:
			LinearLayout l10 = new LinearLayout(context);
			// ImageView iv=new ImageView(context);
			TextView tv10 = new TextView(context);
			tv10.setText(item[position]);
			tv10.setTextSize(DisplayUtil.sp2px(context, 8));
			tv10.setPadding(20, 0, 0, 0);
			tv10.setTextColor(context.getResources().getColor(R.color.gray_9));
			l10.setBackgroundResource(R.color.gray_e6e6e6);
			l10.addView(tv10);
			return l10;
		default:// 这里是附近使用者、附近的活动、我的资料、等等等等
			l4 = new LinearLayout(context);
			ImageView iv3 = new ImageView(context);
			TextView tv3 = new TextView(context);
			iv3.setImageResource(img1[position]);
			iv3.setPadding(20, 10, 10, 10);
			tv3.setText(item[position]);
			tv3.setPadding(10, 10, 10, 10);
			l4.addView(iv3);
			l4.addView(tv3);
			LinearLayout l5 = new LinearLayout(context);
			l5.setLayoutParams(new LinearLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 0.1f));
			l4.addView(l5);
			/** b6是显示提示的数字的 */
			Button b6 = new Button(context);

			b6.setFocusable(false);
			b6.setClickable(false);
			// 然后是position6 7 8 9 11

			switch (position) {
			// 咨询费
			case 8:
				LayoutInflater inflater = LayoutInflater.from(context);
				View view = inflater.inflate(R.layout.after_landing_btn_item,
						null);
				TextView item = (TextView) view.findViewById(R.id.item);
				if (userInfoModel != null) {
					if (userInfoModel.getAdvisory_fees() != null) {
						item.setText("" + userInfoModel.getAdvisory_fees()
								+ "RMB");
					} else {
						item.setText("" + Message[0] + " RMB");
					}
				}
				l4.addView(view);
				break;
			// 朋友
			case 9:
				// Intent intent=new Intent();

				LayoutInflater inflater1 = LayoutInflater.from(context);
				View view1 = inflater1.inflate(R.layout.after_landing_btn_item,
						null);
				TextView item1 = (TextView) view1.findViewById(R.id.item);
				if (userInfoModel != null) {
					if (userInfoModel.getFriend_count() != null) {
						item1.setText("" + userInfoModel.getFriend_count());
					} else {
						item1.setText("" + Message[0]);
					}
				}
				l4.addView(view1);
				break;
			case 10:// 金币数量
				LayoutInflater inflater2 = LayoutInflater.from(context);
				View view2 = inflater2.inflate(R.layout.after_landing_btn_item,
						null);
				TextView item2 = (TextView) view2.findViewById(R.id.item);
				if (userInfoModel != null) {
					if (userInfoModel.getGold() != null) {
						item2.setText("" + userInfoModel.getGold());
					} else {
						item2.setText("" + Message[0]);
					}
				}
				l4.addView(view2);
				break;
			// // 收藏
			// case 10:
			//
			// b6.setBackgroundResource(R.drawable.shape_after_title);
			// b6.setLayoutParams(new LinearLayout.LayoutParams(DisplayUtil
			// .dip2px(context, 40), DisplayUtil.dip2px(context, 30)));
			// if (userInfoModel != null) {
			// if (userInfoModel.getGold() != null) {
			// b6.setText("" + userInfoModel.getGold());设定
			// } else {
			// b6.setText("" + Message[2]);
			// }
			//
			// }
			// b6.setTextSize(DisplayUtil.px2sp(context, 15));
			//
			// b6.setGravity(Gravity.CENTER);
			//
			// l4.addView(b6);
			// break;
			// // 收藏
			// case 9:
			// b6.setBackgroundResource(R.drawable.shape_after_title);
			// b6.setLayoutParams(new LinearLayout.LayoutParams(
			// DisplayUtil.dip2px(context, 40), DisplayUtil.dip2px(context,
			// 30)));
			// b6.setText("" + Message[3]);
			// b6.setTextSize(DisplayUtil.px2sp(context, 15));
			//
			// b6.setGravity(Gravity.CENTER);
			// l4.addView(b6);
			// break;
			// 管理俱乐部
			case 13:

				LayoutInflater inflater3 = LayoutInflater.from(context);
				View view3 = inflater3.inflate(R.layout.after_landing_btn_item,
						null);
				TextView item3 = (TextView) view3.findViewById(R.id.item);
				if (userInfoModel != null) {
					if (userInfoModel.getClub_count() != null) {
						item3.setText("" + userInfoModel.getClub_count());
					} else {
						item3.setText("" + Message[0]);
					}
				}
				l4.addView(view3);

				break;

			// 申请表
			case 14:
				LayoutInflater inflater4 = LayoutInflater.from(context);
				View view4 = inflater4.inflate(R.layout.after_landing_btn_item,
						null);
				TextView item4 = (TextView) view4.findViewById(R.id.item);
				if (userInfoModel != null) {
					if (userInfoModel.getApplyCount() != null) {
						item4.setText("" + userInfoModel.getApplyCount());
					} else {
						item4.setText("" + Message[0]);
					}
				}
				l4.addView(view4);
				break;

			}

			l4.setGravity(Gravity.CENTER_VERTICAL);
		}

		return l4;
	}

	private class ViewHolder {
		ImageView dongtai, tupian, jilu, julebu, zhuti;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.after_landing_btn_setting:
			((AfterLandingActivity) context).setOnChangeToSettingFragment();
			break;
		case R.id.dongtai:
			((AfterLandingActivity) (context)).jiazai(9);
			((AfterLandingActivity) (context)).OpenOrCloseSlidingMenu();
			break;
		case R.id.tupian:
			intent = new Intent(context, MyPoly1Activity.class);
			break;
		case R.id.jilu:
			intent = new Intent(context, RecordMyRecordListActivity.class);
			intent.putExtra("uid", Utils.getUid(context));
			break;
		case R.id.julebu:
			// ((AfterLandingActivity)(context)).jiazai(8);
			// ((AfterLandingActivity)(context)).OpenOrCloseSlidingMenu();
			intent = new Intent(context, ClubMyClubActivity.class);
			intent.putExtra("uid", Utils.getUid(context));
			break;
		case R.id.zhuti:
			intent = new Intent(context, CalendarMyActivityActivity.class);
			intent.putExtra("uid", Utils.getUid(context));
			break;
		case R.id.head:
			intent = new Intent(context, MyDataActivity.class);
			intent.putExtra("uid", Utils.getUid(context));
			break;
		}
		if (intent != null) {
			context.startActivity(intent);
			intent = null;
		}
	}

}
